package cn.dengta.webapp.user.model;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import javax.annotation.Nullable;

import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.annotation.JSONType;
import lombok.Getter;
import lombok.Setter;
import me.codeplayer.util.EasyDate;

@Getter
@Setter
@JSONType(ignores = { "beginTime", "endTime" })
public class GroupVipRule implements Serializable {

	public static final String GROUP_MEMBER = "gm";
	public static final String GROUP_NUMBER = "gn";
	public static final String GROUP_ADMIN = "ga";
	public static final String ALL_SEARCH_NUMBER = "asn";
	public static final String PRIVATE_CHAT_NUMBER = "pcn";

	/** 天数 -1=表示无限制 */
	@JSONField(name = "nb")
	private int number = -1;
	/** 群人数限制 -1=表示无限制 */
	@JSONField(name = GROUP_MEMBER)
	private int groupMember = -1;
	/** 群个数限制 -1=表示无限制 */
	@JSONField(name = GROUP_NUMBER)
	private int groupNumber = -1;
	/** 群管理员限制 -1=表示无限制 */
	@JSONField(name = GROUP_ADMIN)
	private int groupAdmin = -1;
	/** 全局搜索设置 5次/日 -1=表示无限制 */
	@JSONField(name = ALL_SEARCH_NUMBER)
	@Nullable
	private Integer allSearchNumber;
	/** 私聊文字聊天免费次数（每月） -1=表示无限制 */
	@JSONField(name = PRIVATE_CHAT_NUMBER)
	private int privateChatNumber = -1;
	/** 等级：1=VIP; 2=SVIP; 3=SSVIP; 4=SUPER VIP; 5=TOP VIP */
	private Integer level;

	/**
	 * 获取结束时间
	 */
	public Date getEndTime() {
		return getEndTimeFormat(new Date());
	}

	public Date getEndTime(Date date) {
		return getEndTimeFormat(date);
	}

	private Date getEndTimeFormat(Date date) {
		final EasyDate d = number == -1 ? new EasyDate(2099, 12, 31) : new EasyDate(date).addDay(this.number);
		return d.endOf(Calendar.DAY_OF_MONTH).toDate();
	}

}
